home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WarriorsProgress.sit / Warrior’s Progress / source code / Source / Libraries / Dates / DateObject.cp next >
Text File  |  1997-06-28  |  2KB  |  102 lines

  1. // DateObject.cp
  2.  
  3. #ifndef DateObject_h
  4. #include "DateObject.h"
  5. #endif
  6.  
  7. Handle DateObject::Intl0Resource()
  8.   {
  9.     static Handle resource = GetIntlResource( 0 );
  10.     return resource;
  11.   }
  12.  
  13. Handle DateObject::Intl1Resource()
  14.   {
  15.     static Handle resource = GetIntlResource( 1 );
  16.     return resource;
  17.   }
  18.  
  19. DateCacheRecord *DateObject::MakeCache()
  20.   {
  21.     static DateCacheRecord cache;
  22.     InitDateCache( &cache );
  23.     return &cache;
  24.   }
  25.  
  26. DateCacheRecord *DateObject::Cache()
  27.   {
  28.     static DateCacheRecord *cache( MakeCache() );
  29.     return cache;
  30.   }
  31.  
  32. DateObject DateObject::Now()
  33.   {
  34.     uint32 now;
  35.     GetDateTime( &now );
  36.     return now;
  37.   }
  38.  
  39. void DateObject::operator=( ConstData text )
  40.   {
  41.     LongDateRec date;
  42.     
  43.     int32 used;
  44.     StringToDateStatus result = StringToDate( (Ptr)text.Start(),
  45.                                                             text.Length(),
  46.                                                             Cache(),
  47.                                                             &used,
  48.                                                             &date );
  49.     
  50.     const StringToDateStatus okResults = longDateFound | leftOverChars;
  51.  
  52.     Assert( used > 0 );
  53.     Assert( ( result & ~okResults ) == 0 );
  54.     
  55.     text.Shorten( used );
  56.     if ( !text.IsEmpty() )
  57.       {    
  58.         result = StringToTime( (Ptr)text.Start(),
  59.                                       text.Length(),
  60.                                       Cache(),
  61.                                       &used,
  62.                                       &date );
  63.         
  64.         Assert( used == text.Length() );
  65.         Assert( result == noErr );
  66.       }
  67.     
  68.     LongDateTime time;
  69.     LongDateToSeconds( &date, &time );
  70.     
  71.     secondsFrom1904 = time.lo;
  72.   }
  73.  
  74. void DateObject::WriteDate( String255& string ) const
  75.   {
  76.     LongDateTime time;
  77.     time.hi = secondsFrom1904 >> 32;
  78.     time.lo = secondsFrom1904;
  79.     
  80.     LongDateString( &time, longDate, string, Intl1Resource() );
  81.   }
  82.  
  83. void DateObject::WriteTime( String255& string ) const
  84.   {
  85.     LongDateTime time;
  86.     time.hi = secondsFrom1904 >> 32;
  87.     time.lo = secondsFrom1904;
  88.     
  89.     LongTimeString( &time, true, string, Intl0Resource() );
  90.   }
  91.  
  92. void DateObject::WriteDateAndTime( String255& string ) const
  93.   {
  94.     WriteDate( string );
  95.     
  96.     String255 timeString;
  97.     WriteTime( timeString );
  98.     
  99.     string += "\p ";
  100.     string += timeString;
  101.   }
  102.